<?php

class DBMCommand {
	/**
	 * The operation that this command will execute
	 *
	 * @var int
	 */
	private $operation = null; 

	/**
	 * The entities related with this
	 *
	 * @var array<DBMEntity>
	 */
	private $entities = array();

	/**
	 * The joins
	 *
	 * @var array<DBMJoin>
	 */
	private $joins = array();
	
	/**
	 * The ordenators
	 *
	 * @var array The ordenators
	 */
	private $ordenators = array();
	
	/**
	 * The filters related with this
	 *
	 * @var array<DBMFIlter>
	 */
	private $filters = array();
	
	/**
	 * The limit of results
	 *
	 * @var int
	 */
	private $resultLimit = null;
	
	/** gets / sets */
	public function getOperation(){
		return $this->operation;
	}
	public function getEntities(){
		return $this->entities;
	}
	public function getJoins(){
		return $this->joins;
	}
	public function getOrdenators(){
		return $this->ordenators;
	}
	public function getFilters(){
		return $this->filters;
	}
	public function getResultLimit(){
		return $this->resultLimit;
	}
	public function setOperation($operation){
		$this->operation = $operation;
	}
	public function setEntities($entities){
		$this->entities = $entities;
	}
	public function setJoins($joins){
		$this->joins = $joins;
	}
	public function setOrdenators($ordenators){
		$this->ordenators = $ordenators;
	}
	public function setFilters($filters){
		$this->filters = $filters;
	}
	public function setResultLimit($resultLimit){
		$this->resultLimit = $resultLimit;
	}
	
	/**
	 * Return the main entity of the command
	 *
	 * @return DBMEntity The main entity
	 */
	public function getMainEntity(){
		reset($this->entities);
		return current($this->entities);
	}
	
	/**
	 * Add a new entity to this command
	 *
	 * @param DBMEntity $entity
	 */
	public function addEntity(DBMEntity $entity){
		// register the entity
		$this->entities[$entity->getName()] = $entity;
	}

	/**
	 * Add the join to this command
	 *
	 * @param DBMJoin $join
	 */
	public function addJoin(DBMJoin $join){
		$this->joins[] = $join;
	}
	
	/**
	 * Add the ordenator to this command
	 *
	 * @param DBMOrdenator $ordenator
	 */
	public function addOrdenator(DBMOrdenator $ordenator){
		$this->ordenators[] = $ordenator;
	}
	
	/**
	 * Add a new filter to this command
	 *
	 * @param DBMFilter $filter
	 */
	public function addFilter(DBMFilter $filter){
		// register the table
		$this->filters[] = $filter;
	}
}

?>
